<template>
  <div>
    <van-nav-bar title="黑马头条-首页"/>
<van-form @submit="onSubmit">
  <van-field
    type="tel"
    v-model="formLongin.mobile"
    name="手机号"
    label="手机号"
    placeholder="请输入手机号"
    required
    :rules="[{ required: true, message: '请正确填写用户名' ,pattern:/^1[3-9]\d{9}$/,trigger:'onChange'}]"
  />
  <van-field
    v-model="formLongin.code"
    type="password"
    name="密码"
    label="密码"
    required
    placeholder="请输入密码"
    :rules="[{ required: true, message: '请正确填写密码',pattern:/^\d{6}$/}]"
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit" :loading='isLogin'  loading-text="稍等稍等马上就好..." color="orange">提交</van-button>
  </div>
</van-form>
  </div>
</template>

<script>
import { Notify } from 'vant'
import { mapActions } from 'vuex'
export default {
  data () {
    return {
      isLogin: false,
      formLongin: {
        mobile: '13888888888',
        code: '246810'
      }
    }
  },
  methods: {
    ...mapActions(['asyncLoginAction']),
    async onSubmit () {
      this.isLogin = true
      try {
        this.isLogin = false
        await this.asyncLoginAction(this.formLongin)
        Notify({ type: 'success', message: '登录成功' })
        // 跳转到Layout页面
        this.$router.replace({
          path: '/layout'
        })
        console.log(222)
      } catch (err) {
        this.isLogin = false
        Notify({ type: 'warning', message: '手机号或密码错误' })
        console.log(err)
      }
    }
  }
}
</script>

<style lang="less" scoped>
// .van-nav-bar {
//   background-color: rgb(255, 132, 0);
// }
//层级更深了 摸不到
//  /deep/ 穿透 为了防止不生效
// /deep/ .van-nav-bar__title {
//   color:#fff;
// }

</style>
